package chapter6;

/**
 * yield并不会释放掉同步锁
 * Created by LinGer on 2019/6/18
 */
public class YieldTest extends Thread {

    public YieldTest(String name){
        super(name);
    }

    @Override
    public synchronized void run() {
        for (int i = 0; i < 10; i++) {
            //getPriority()获取当前线程的优先级
            System.out.println(Thread.currentThread().getName() + " [" + Thread.currentThread().getPriority() + "] : " + i);

            //i整除4时，调用yield
            if(i % 4 == 0){
                Thread.yield();
            }
        }
    }

    public static void main(String[] args) {
        YieldTest t1 = new YieldTest("t1");
        YieldTest t2 = new YieldTest("t2");

        t1.start();
        t2.start();
    }
}
